<?php namespace Member\Controller;
use Hdphp\Controller\Controller;
use Member\Model\User;
class UserController extends Controller{
	protected $db;
	//构造函数
	public function __init(){
		$this->db = new User;
	}
    //动作
	public function register(){
		if (IS_POST)
		{
			if($this->db->reg()){
				View::success('注册成功',$_SESSION['history']);
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			$_SESSION['history'] = __HISTORY__;
			View::make('register.html');
		}
	}
    //动作
	public function login(){
		if(IS_POST)
		{
			if($this->db->login()){
				if(!isset($_SESSION['module'])){
					$url = $_SESSION['history'];
					unset($_SESSION['history']);
					View::success('登录成功',$url);
				}else
				{
					echo "string";
					$controller = $_SESSION['controller'];
					$action = $_SESSION['action'];
					unset($_SESSION['module']);
					unset($_SESSION['controller']);
					unset($_SESSION['action']);
					go('Member/'.$controller.'/'.$action);
				}
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			$_SESSION['history'] = __HISTORY__;
			View::make('login.html');
		}
	}
	public function code()
	{
		Code::make();
	}
	//退出
	public function quit()
	{
		session_unset();
		session_destroy();
		go('login');
	}
}
